# This file is intended to be a final submission. python tester.py Player.py
# should work at all times. If it does not, there is a bug.
# If you're just trying to test a solution, scroll down to the Player
# class.

# This file is intended to be in the same format as a valid solution, so
# that users can edit their solution into Player and then submit just this
# file to the contest. If you see any reason this would not work, please submit
# an Issue to https://github.com/ChadAMiller/hungergames/issues or email me.

# You can see more sample player classes in bots.py

class BasePlayer(object):
    '''
    Base class so I don't have to repeat bookkeeping stuff.
    Do not edit unless you're working on the simulation.
    '''
    
    def __str__(self):
        try:
            return self.name
        except AttributeError:
            # Fall back on Python default
            return super(BasePlayer, self).__repr__()
    
    def hunt_choices(*args, **kwargs):
        raise NotImplementedError("You must define a strategy!")
        
    def hunt_outcomes(*args, **kwargs):
        pass
        
    def round_end(*args, **kwargs):
        pass


class Player(BasePlayer):
    '''
    Your strategy starts here.
    '''

    def __init__(self):
        self.name = 'Core_Test'
        self.coop = []
        self.players = 0
        self.top_hunters = 0
        self.sorted_reputations = []
        self.feeder = 0
        self.current_coop = 0
        self.slacker = 0
        self.betray = 0
        self.current_round = 1

    def hunt_choices(
                    self,
                    round_number,
                    current_food,
                    current_reputation,
                    m,
                    player_reputations,
                    ):
        '''Required function defined in the rules'''
        choices = []
        self.players = len(player_reputations)
        self.sorted_reputations = sorted(player_reputations, reverse=True)
        self.current_round = round_number%11
        if 1 <= self.current_round <= 2:
            # Establishment
            if self.current_round == 1:
                # Send signal 'h'
                return ['h'] * self.players
            elif self.current_round == 2:
                # Wait for their signal
                return ['s'] * self.players
        elif 3 <= self.current_round <= 8:
            # Cooperation
            # Hunt with everyone that gave signals. If they betray during this, remove them and wait for round 11*x+1
            for i in range(self.players):
                choices.append('h') if player_reputations[i] in self.sorted_reputations[self.feeder:self.current_coop] else choices.append('s')
            return choices

        elif 9 <= self.current_round <= 11:
            # Betrayal
            # It is time to betray all with whom we were cooperating.
            return ['s'] * self.players
        else:
            return ['s'] * self.players
        

    def hunt_outcomes(self, food_earnings):
        '''Required function defined in the rules'''
        food_earnings = sorted(food_earnings, reverse=True)
        self.top_hunters = 0
        self.feeder = 0
        self.current_coop = 0
        self.slacker = 0
        self.betray = 0
        for i in range(len(food_earnings)):
            if food_earnings[i] == 1:
                self.feeder = i
            elif food_earnings[i] == 0:
                self.current_coop = i
            elif food_earnings[i] == -2:
                self.slacker = i
            elif food_earnings[i] == -3:
                self.betray = i

        if self.current_coop == 0:
            self.current_coop = self.feeder
        if self.slacker == 0:
            self.slacker = self.coop
        if self.betray == 0:
            self.betray = self.slacker

        if self.current_round == 2:
            self.current_coop = self.feeder
            self.feeder = 0
        pass
        

    def round_end(self, award, m, number_hunters):
        '''Required function defined in the rules'''
        pass
        
'''
    Comment area

    Rounds: Cycle of 11
    Establishment round: 1,2 (2)
    Hunting round with coops: till 8 (6 rounds)
    Betray round: 9,10,11 (3)
    Establishment: 12,13
    continue...

'''